package cn.virens.common.boot.dubbo.error.simple;

import cn.virens.common.boot.dubbo.error.VirensExceptionHandler;
import cn.virens.common.util.exception.APIException;
import org.apache.dubbo.common.extension.Activate;
import org.springframework.dao.DataIntegrityViolationException;

@Activate
public class VirensExceptionWithDataIntegrityException implements VirensExceptionHandler {
    @Override
    public APIException exceptionHandling(Throwable e) throws APIException {
        if (e instanceof DataIntegrityViolationException exception) {
            return new APIException("DATA_ERR", "请检查约束");
        }

        return null;
    }
}
